class TransitionModes < Application
  before :find_mode, :exclude => [ :new, :create, :index ]
  
  def index
    only_provides :xml
    @title = 'TransitionMode-View'
    render
  end
  
  def show
    provides :xml, :html
    @title = 'TransitionMode-View'
    case content_type
    when :html
      render
    when :xml
      @mode.to_xml
    end
  end
  
  def undo
    only_provides :xml
    begin
      @mode.undo
      self.headers[:Location] = request.referer
      self.status = 301
      return ""
    rescue Exception => e
      Merb.logger.error(e)
      Merb.logger.error(e.backtrace.join("\n"))
  
      self.status = 500
      return ""
    end
  end
  
  def redo
    only_provides :xml
    begin
      @mode.redo
      self.headers[:Location] = request.referer
      self.status = 301
      return ""
    rescue Exception => e
      Merb.logger.error(e)
      Merb.logger.error(e.backtrace.join("\n"))
  
      self.status = 500
      return ""
    end
  end
  private
    def find_mode
      @mode = PNEngine::TransitionMode.find(params[:id])
    end
end
